package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/*
    统计一个字符串在字符串中出现的次数
 */
public class Test {
    public static void main(String[] args) {
        String line ="i love java! thinking in java!! hello world";
        Map<Character,Integer> map = new HashMap<>();

        for (int i=0;i<line.length();i++){
//            System.out.println(line.charAt(i));
            char c =line.charAt(i);
            if (map.containsKey(c)){
                int num = map.get(c);
                num++;
                map.put(c,num);
            }else{
                map.put(c,1);
            }
        }
//        System.out.println(map);
        map.forEach((k,v)-> System.out.print(k+":"+v+"  "));
    }
}
